package vip.xls8z.learning.bio.server;

import lombok.extern.slf4j.Slf4j;

import java.io.*;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Slf4j
public class BioEchoServer {

    public static void main(String[] args) throws IOException {
        ExecutorService executorService = Executors.newFixedThreadPool(4);
        ServerSocket serverSocket = new ServerSocket();
        serverSocket.bind(new InetSocketAddress("127.0.0.1", 8099));
        boolean flag = true;
        while (flag) {
            Socket socketClient = serverSocket.accept();
            executorService.execute(new BioEchoHandler(socketClient));
        }
        executorService.shutdown();
    }
}
